package com.xc.file.web.rest;

import com.xc.core.annotation.Authority;
import com.xc.core.model.TokenModel;
import com.xc.file.dto.UserDiskInfoDto;
import com.xc.file.entity.UserInfoEntity;
import com.xc.file.service.UserInfoService;
import com.xc.tool.utils.ObjectUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>用户网盘信息</p>
 *
 * @author xc
 * @version v1.0.0
 */
@Api(tags = {"用户网盘信息"})
@RestController
public class UserInfoRest {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "获取当前用户网盘信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户token", name = "token", paramType = "header", required = true)
    })
    @GetMapping(value = "/current_user/disk_info")
    @Authority
    public UserDiskInfoDto getUserDiskInfo(TokenModel tokenModel) {
        UserInfoEntity userInfoEntity = userInfoService.getUserInfoByUserId(tokenModel.getUserId());
        UserDiskInfoDto userDiskInfoDto = ObjectUtils.convert(new UserDiskInfoDto(), userInfoEntity);
        userDiskInfoDto.setUseSpace(userInfoService.getUseSpace(tokenModel.getUserId()));
        return userDiskInfoDto;
    }
}
